package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.partner.PartnerInsiderSettleLogMapper;
import com.net.xpay.common.domain.partner.PartnerInsiderSettleLog;
import com.net.xpay.common.manager.partner.PartnerInsiderSettleLogManager;
import com.net.xpay.core.model.PartnerInsiderSettleLogSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;


@Component
public class PartnerInsiderSettleLogManagerImpl extends AbstractManager<PartnerInsiderSettleLog> implements PartnerInsiderSettleLogManager{

    @Autowired
    private PartnerInsiderSettleLogMapper mapper;


    @Override
    protected BasicMapper<Long, PartnerInsiderSettleLog> getMapper() {
        return mapper;
    }



    @Override
    public List<PartnerInsiderSettleLog> search(PartnerInsiderSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(PartnerInsiderSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public BigDecimal sumPartnerSettleAmount(PartnerInsiderSettleLogSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.sumPartnerSettleAmount(searchModel);
    }

    @Override
    public PartnerInsiderSettleLog findByMonthOfYear(Integer year, Integer month, Long userId) {
        Preconditions.checkArgument(year != null && month != null && userId != null);
        PartnerInsiderSettleLog condition = new PartnerInsiderSettleLog();
        condition.setUserId(userId);
        condition.setYear(year);
        condition.setMonth(month);
        return getByCondition(condition);
    }
}
